#include  <iostream>
using namespace std;
struct student{
    string no;
    int trySeat;
    int realSeat;
};

int main()
{
    int N;
    cin>>N;
    student a[1000];
    for(int i =0; i<N; i++)
        cin>>a[i].no>>a[i].trySeat>>a[i].realSeat;
    int times;
    cin>>times;
    for(int i = 0; i<times; i++)
    {
        int trySeat;
        cin>>trySeat;
        for(auto e: a)
        {
            if(e.trySeat == trySeat)
            {
                cout<<e.no<<" "<<e.realSeat<<endl;
                break;
            }
        }
    }
    
}